package com.mzpai.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mzpai.mapper.BaseMapper;
import com.mzpai.model.BaseModel;
import com.mzpai.service.BaseService;
import com.mzpai.util.PageUtil;


public abstract class BaseServiceImpl<T extends BaseModel> implements BaseService<T> {
	
	@Autowired
	private BaseMapper<T> mapper;
	/**
	 * 删除
	 * @param id
	 */
	public void delete(String id) {
		mapper.delete(id);
	}
	/**
	 * 保存
	 * @param target
	 */
    public int save(T target){
    	return mapper.insert(target);
    }
    
    /**
     * 修改
     * @param target
     */

    public int update(T target) {
    	return mapper.update(target);
    }
    
    /**
     * 查询
     * @param map
     * @return
     */
    public PageInfo<T> getListPage(Map<String, Object> map, Integer pageNum, Integer pageSize){
    	PageHelper.startPage(pageNum, pageSize);
		return PageUtil.toPageInfo(mapper.getList(map));
    }
    
    /**
     * 根据ID，查询信息
     * @param id
     * @return
     */
    
    public T queryById(String id){
    	return mapper.queryById(id);
    }


    /**
     * 查询所有
     * @param map
     * @return
     */
    public List<T> getList(Map<String, Object> map) {
    	return mapper.getList(map);
    }
	
}
